#ifndef wave_reader_h__
#define wave_reader_h__

#include <boost/shared_ptr.hpp>
#include <vector>

#include "wave_structs.h"

class WaveReader
{
public: 
  typedef boost::shared_ptr<WaveReader> WaveReaderPtr;

  static WaveReaderPtr GetInstance(const std::string &wavePath = "source.wav")
  {
    if (ins.use_count() == 0)
    {
      ins.reset(new WaveReader(wavePath));
    }
    return ins;
  }

  RIFF GetRiff() const { return riff; }
  WAVE GetWave() const { return wave; }
  DATA GetData() const { return data; }
  DWORD GetBitarate() const { return wave.desc.nSamplesPerSec; }
  long GetDataSize() const { return data.size; }

  short at(int n) const 
  {
    if (n >= buff.size())
    {
      return 0;
    }
    return buff.at(n);
  }

private:
  static WaveReaderPtr ins;
  RIFF riff;
  WAVE wave;
  DATA data;
  std::vector<short> buff;

  WaveReader(const std::string &wavePath);
  bool Init(const std::string &wavePath);
};

#endif // wave_reader_h__